
from apps.common.base.serializers import *
from apps.pay.recordIncomes.models import *

class RecordIncomesBaseSerializer(BaseSerializer):

    class Meta:
        model = RecordIncomes
        fields = "__all__"

class RecordIncomesModelSerializer(BaseSerializer):

    userModel = serializers.SerializerMethodField()
    def get_userModel(self, obj):
        if obj.user:
            return {'id': obj.user.id, 'nickname': obj.user.nickname, 'code': obj.user.code, 'phone': obj.user.phone}
        else:
            return {}
        
    fromUserModel = serializers.SerializerMethodField()
    def get_fromUserModel(self, obj):
        if obj.fromUser:
            return {'id': obj.fromUser.id, 'nickname': obj.fromUser.nickname, 'code': obj.fromUser.code, 'phone': obj.fromUser.phone}
        else:
            return {}

    payWayAccountModel = serializers.SerializerMethodField()
    def get_payWayAccountModel(self, obj):
        if obj.payWayAccount:
            typesDict = {
                'ali': '支付宝', 
                "wx": '微信',
                'bank': '银行卡'
            }
            return {'id': obj.payWayAccount.id, 'types': typesDict.get(obj.payWayAccount.types), 'accountName': obj.payWayAccount.accountName, 'account': obj.payWayAccount.account, 'paywayCodeUrl': obj.payWayAccount.paywayCodeUrl }
        else:
            return {}

    sceneLabel = serializers.SerializerMethodField()
    def get_sceneLabel(self, obj):
        if obj.scene:
            return obj.get_scene_display()
        else:
            return ''

    orderStatusLabel = serializers.SerializerMethodField()
    def get_orderStatusLabel(self, obj):
        if obj.orderStatus:
            return obj.get_orderStatus_display()
        else:
            return ''

    class Meta:
        model = RecordIncomes
        fields = "__all__"